<?php
/**
* Author: Porlock
* Link: www.porlockz.com
* Date: 2018-04-03 16:29:57
* Last Modified time: 
*/
/**
 * 动态展示题目
 * @param  [type] $dbh   [数据库连接]
 * @param  [type] $query [查询语句]
 * @param  [type] $type  [类型]
 * @return [type]        [返回html页面]
 */
function challenge($dbh,$query,$type,$uid){
	$sth = $dbh->prepare($query);
	$sth -> execute();
	$rownum = $sth -> rowCount();
	echo <<<web_start
	<fieldset class="layui-elem-field layui-field-title">
	        <legend style="font-size: 30px">$type</legend>
web_start;
	for($i = 0;$i < $rownum;$i++){
		$result      = $sth -> fetch();
		$tid         = $result['tid'];
		$title       = $result['title'];
		$point       = $result['point'];
		$description = $result['description'];
		$link        = $result['link'];
		$solved      = $result['solved'];
	    // 获取该题解答情况
		$query_solved = "SELECT * FROM `solved_situation` WHERE `tid` = :tid AND `uid` = :uid";
		$sth_solved   = $dbh->prepare($query_solved);
		$sth_solved -> bindParam(":tid",$tid);
		$sth_solved -> bindParam(":uid",$uid);
		$sth_solved -> execute();
		$solveThis    = $sth_solved -> fetch();
		if(!empty($solveThis)){
		    $solveResult = 1;
		}
		else{
		    $solveResult = 0;
		}
	    if($i % 4 === 0){
	        echo <<<challenge_block_start
	        <div class="layui-row layui-col-space60">
challenge_block_start;
	    }
	    if($solveResult === 0){
		    echo <<<challenge_block_UnSolvedContent
			    <div class="layui-col-md3">
			        <button class="layui-btn layui-btn-lg layui-btn-fluid" style="height:auto;background-color: #343A40" id="func1" onclick="tab('$title','$point','$description','$link',$solved);">
			            <p>$title</p>
			            <span>$point</span>
			        </button>
			    </div>
challenge_block_UnSolvedContent;
}
	    elseif($solveResult === 1){
			echo <<<challenge_block_SolvedContent
			    <div class="layui-col-md3">
			        <button class="layui-btn layui-btn-lg layui-btn-fluid" style="height:auto;background-color: #43CD80" id="func1" onclick="tab('$title','$point','$description','$link',$solved);">
			            <p>$title</p>
			            <span>$point</span>
			        </button>
			    </div>
challenge_block_SolvedContent;
	    }
	    if($i % 4 === 3){
	        echo <<<challenge_block_end
	        </div>
challenge_block_end;
	    }
	}
	echo <<<challenge_block_end
		</fieldset>
challenge_block_end;
}